test_description="quarantine-helper display"

. ./lib/sharness.sh

Quaranine="*incoming*"

test_expect_success "setup" '
	git init --bare remote.git &&
	cp "$HOME/../resources/pre-receive" remote.git/hooks/
'

test_expect_success "scan quarantine(one commit)" '
    cp -r remote.git tmp-remote.git &&
    git clone --no-local remote.git local &&
	(
		cd local &&
		generate_commits 0 0 &&
		git push
	) &&
	cat >expect<<-EOF &&
	-088084-6201bff8206a22207277d0e64bac92ec01f5cb10-088084-file0
	-088084-C O Mitter-088084-committer@example.com-088084-2005-04-07T15:13:13-07:00-088084-A U Thor-088084-author@example.com-088084-2005-04-07T15:13:13-07:00-088084-
	EOF
	GIT_DIR=local/.git quarantine-helper scan -q $Quaranine | \
    quarantine-helper filter -q $Quaranine -r tmp-remote.git -b 6201bff8206a22207277d0e64bac92ec01f5cb10 | \
    quarantine-helper display -q $Quaranine -r tmp-remote.git -d '-088084-' --commitID --message --committedTime --committerName \
	--committerEmail --authoredTime --authorName --authorEmail >actual &&
	echo "" >>actual &&
	test_cmp expect actual
'

test_expect_success "scan quarantine(5 commits)" '
	rm -rf $Quaranine &&
	rm -rf tmp-remote.git &&
    cp -r remote.git tmp-remote.git &&
	(
		cd local &&
		generate_commits 1 5 &&
		git push
	)
	cat >expect<<-EOF &&
	-088084-4272e5f09914017057bc328da23de529a23dc946-088084-file5
	-088084-C O Mitter-088084-committer@example.com-088084-2005-04-07T15:17:13-07:00-088084-A U Thor-088084-author@example.com-088084-2005-04-07T15:17:13-07:00-088084--088084-1b92441c9aeca6a9b4b1df3f24e2ecbea7ec4096-088084-file4
	-088084-C O Mitter-088084-committer@example.com-088084-2005-04-07T15:16:13-07:00-088084-A U Thor-088084-author@example.com-088084-2005-04-07T15:16:13-07:00-088084--088084-c70a396ef27abad5199144f6287a3b891e097c11-088084-file3
	-088084-C O Mitter-088084-committer@example.com-088084-2005-04-07T15:15:13-07:00-088084-A U Thor-088084-author@example.com-088084-2005-04-07T15:15:13-07:00-088084--088084-042f968d17d76f896591fe05454208ecd64291a5-088084-file2
	-088084-C O Mitter-088084-committer@example.com-088084-2005-04-07T15:14:13-07:00-088084-A U Thor-088084-author@example.com-088084-2005-04-07T15:14:13-07:00-088084--088084-54a2d8b0c097f71e3e43c046ad2beb51bbbf2955-088084-file1
	-088084-C O Mitter-088084-committer@example.com-088084-2005-04-07T15:13:13-07:00-088084-A U Thor-088084-author@example.com-088084-2005-04-07T15:13:13-07:00-088084-
	EOF
	GIT_DIR=local/.git quarantine-helper scan -q $Quaranine | \
    quarantine-helper filter -q $Quaranine -r tmp-remote.git -b 4272e5f09914017057bc328da23de529a23dc946 | \
    quarantine-helper display -q $Quaranine -r tmp-remote.git -d '-088084-' --commitID --message --committedTime --committerName \
	--committerEmail --authoredTime --authorName --authorEmail >actual &&
	echo "" >>actual &&
	test_cmp expect actual
'

test_expect_success "new branch with no new commits" '
	rm -rf $Quaranine &&
    cp -r remote.git tmp-remote.git &&
	(
		cd local &&
		git checkout -b topic1&&
		git push -u origin topic1
	) &&
	GIT_DIR=local/.git quarantine-helper scan -q $Quaranine | \
    quarantine-helper filter -q $Quaranine -r tmp-remote.git -b b735449c594ce6d148f4640792d5bbae2cddb1d5 | \
    quarantine-helper display -q $Quaranine -r tmp-remote.git -d '-088084-' --commitID --message --committedTime --committerName \
	--committerEmail --authoredTime --authorName --authorEmail >actual &&
	test -f actual && test ! -s actual
'

test_done